<?php
$this->breadcrumbs=array(
	'Portfolios'=>array('index'),
	'Create',
);

include "menu.php";
?>

<h1>Component Portfolio</h1>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'exchanges-form',
	'enableAjaxValidation'=>false,
)); ?>
<input name="component_port" id="component_port" type="hidden" value="<?PHP echo $port; ?>">
<?php
if (isset($_GET['port']))
    $tickerCount = Portfolio::model()->findAll(array('select' => 'companyID', 'distinct' => true, 'condition' => "portfolionameID = " . $port));
else
    $tickerCount = "0";

?>
<?PHP
echo "<table><tr><th>Ticker</th><th>Date</th><th>Quantity</th></tr>";
foreach($tickerCount as $temp_data)
{
	$company = Company::model()->findByAttributes(array('id' => $temp_data->companyID));
	$component_port = Componentportfolio::model()->findByAttributes(array('companyID' => $temp_data->companyID, 'portfolionameID' => $port));
	if(count($component_port) > 0) {
			$pieces = explode(" ", $component_port->date); /// xu ly thong tin ngay bat dau
            $pieces1 = explode("-", $pieces[0]);
			$date_return = $pieces1[2]."/".$pieces1[1]."/".$pieces1[0];
            $datepicker1 = $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'name'=>"date_".$company->id,
                'value'=>$date_return,
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => $company->ticket
                ),
            ), true);
		echo "<tr><td><label>".$company->ticket."</label></td>";
		echo "<td>".$datepicker1."</td><td><input name=\"quantity_".$company->id."\" id=\"".$company->ticket."\" type=\"text\" value=\"".$component_port->quantity."\"></td></tr>";

	} else {
            $datepicker2 = $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'name'=>"date_".$company->id,
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => $company->ticket
                ),
            ), true);
		echo "<tr><td><label>".$company->ticket."</label></td>";
		echo "<td>$datepicker2</td><td><input name=\"quantity_".$company->id."\" id=\"".$company->ticket."\" type=\"text\" value=\"\"></td></tr>";

	}
			//echo $temp_data->companyID."<br>";
}
echo "</table>";
?>
<div class="row buttons">
		<?php echo CHtml::submitButton("Save"); ?>
</div>
<?php $this->endWidget(); ?>

</div><!-- form -->